package values.enlist
{
	public class EnlistNumTemplateValueList
	{
		private static var _initNum:int
		
		public static function get initNum():int
		{
			return _initNum;
		}
		
		public function get initNum():int
		{
			return _initNum;
		}
		
		[Data(type="field" , mapping="@init_num")]
		public function set initNum(value:int):void
		{
			_initNum = value;
		}
		
		private static var _enlistNumArray:Array;

		public static function get enlistNumArray():Array
		{
			return _enlistNumArray;
		}
		
		public function get enlistNumArray():Array
		{
			return _enlistNumArray;
		}
		
		[Data(type="mapping" , mapping="level_num",
				ref="values.enlist.EnlistNumTemplateValue",
				way="one_to_more")]
		public function set enlistNumArray(value:Array):void
		{
			_enlistNumArray = value;
			_enlistNumArray.sortOn("levelStart" , Array.NUMERIC);
		}
		
		public static function getCurrentNum(levelInt:int):int
		{
			var returnNum:int = initNum;
			for each(var entv:EnlistNumTemplateValue in enlistNumArray)
			{
				if(entv.isInThisLevel(levelInt))
				{
					returnNum += entv.getLevelInThisPart(levelInt);
					
					break;
				}
				else
				{
					returnNum += entv.getAllNum();
				}
			}
			
			return returnNum;
		}
		
		public static function getNextLevel(levelInt:int):*
		{
			var addLevel:int = 0;
			var addNum:int = 0;
			for each(var entv:EnlistNumTemplateValue in enlistNumArray)
			{
				if(entv.isInThisLevel(levelInt))
				{
					addLevel = entv.unitLevel - ( ( levelInt - entv.levelStart + 1 ) % entv.unitLevel );
					addNum = entv.unitNum;
					break;
				}
				
			}
			
			return {level:levelInt + addLevel , num:addNum};
		}
		
	}
}